package cn.dnui_lf_705.dnui_16110100705.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dnui_lf_705.dnui_16110100705.R;
import cn.dnui_lf_705.dnui_16110100705.bean.CommentBean;
import cn.dnui_lf_705.dnui_16110100705.controller.FoodInfoActivity;


public class CommentAdapter extends  RecyclerView.Adapter<CommentAdapter.ViewHolder> implements View.OnClickListener{

    private List<CommentBean> mDatalist;
    private Context Context;
    private LayoutInflater mLayoutInflater;
    private String phonenum;

    public CommentAdapter(FoodInfoActivity foodInfoActivity, List<CommentBean> o, int comment_item) {
        this.Context = foodInfoActivity;
        this.mDatalist = o;
        mLayoutInflater = LayoutInflater.from(Context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v =mLayoutInflater.from(viewGroup.getContext()).inflate(R.layout.comment_item,viewGroup,false);
        v.setOnClickListener(this);
        return new CommentAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        final CommentBean entity = mDatalist.get(i);
        if(entity == null)
            return;
        final ViewHolder viewHolder1 = (ViewHolder) viewHolder;
        viewHolder1.username.setText( (String)entity.getUsername());
        viewHolder1.username1.setText(entity.getContent());
        viewHolder1.date.setText(entity.getComment_time());
    }



    @Override
    public int getItemCount() {
        return mDatalist.size();
    }

    @Override
    public void onClick(View v) {

    }

        public class ViewHolder extends RecyclerView.ViewHolder {
        TextView username,username1,date;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            username = itemView.findViewById(R.id.username);
            username1 = itemView.findViewById(R.id.username1);
            date = itemView.findViewById(R.id.riqi);

        }
    }

//    @NonNull
//    @Override
//    public CommentAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
//        View v =mLayoutInflater.from(viewGroup.getContext()).inflate(R.layout.comment_item,viewGroup,false);
//        v.setOnClickListener(this);
//        return new CommentAdapter.ViewHolder(v);
//    }
//
//    @Override
//    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
//        final CommentBean entity = mDatalist.get(i);
//        if(entity == null)
//            return;
//        final ViewHolder viewHolder1 = (ViewHolder) viewHolder;
//        viewHolder1.username.setText( (String)entity.getUsername());
//        viewHolder1.username1.setText(entity.getFoodname()+"吴旭");
//        viewHolder1.date.setText(entity.getComment_time());
//    }
//
//
//    @Override
//    public int getItemCount() {
//        return mDatalist.size();
//    }
//
//    @Override
//    public void onClick(View v) {
//
//    }
//
//    public class ViewHolder extends RecyclerView.ViewHolder {
//        TextView username,username1,date;
//        public ViewHolder(@NonNull View itemView) {
//            super(itemView);
//            username = itemView.findViewById(R.id.username);
//            username1 = itemView.findViewById(R.id.username1);
//            date = itemView.findViewById(R.id.riqi);
//        }
//    }
}
